package chap8;
//************************************************************************
//  PP8_1.java                  Author:GK
//
//  用户存取款方法。
//************************************************************************

import java.text.NumberFormat;
import java.util.Random;

public class Account {
    private final double RATE = 0.03;
    private  long acctNumber;
    private double balance;
    private String name, result;

    public Account(String name, long acctNumber, double balance)
    {
        this.name = name;
        this.acctNumber = acctNumber;
        this.balance = balance;
    }

    //  访问账户名。
    public String getName()
    {
        return name;
    }

    //  访问账户账户。
    public double getNumber()
    {
        return acctNumber;
    }

    //  存钱。
    public double deposit(double amount)
    {
        balance = balance + amount;
        return balance;
    }

    //  取钱。
    public double withdraw(double amount, double fee)
    {
        balance = balance - amount - fee;
        return balance;
    }

    //  利息
    public double addInterest()
    {
        balance += (balance * RATE);
        return balance;
    }

    //  查询余额。
    public double getBalance()
    {
        return balance;
    }

    public String toString()
    {
        NumberFormat fmt = NumberFormat.getCurrencyInstance();
        if (balance < 0 )
            result = "账户：" + name + "\n账号：" + acctNumber + "\n余额不足。";
        else
            result = "账户：" + name + "\n账号：" + acctNumber + "\n余额：" + balance;
        return result;
    }
}
